<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<md-dialog aria-label="Add member" layout-padding flex="30">
  <md-dialog-content class="searchMembers">
    <h4>Add members to {{$ctrl.group.name}}</h4>
    <div layout="row" layout-align="space-between center">
      <span>Choose an API role</span>
      <md-select
        ng-model="$ctrl.defaultApiRole"
        aria-label="API Role"
        class="md-no-underline"
        ng-disabled="!$ctrl.canChangeDefaultApiRole()"
      >
        <md-option ng-repeat="role in $ctrl.apiRoles" ng-value="role.name" ng-disabled="$ctrl.isApiRoleDisabled(role)">
          {{role.name}}
        </md-option>
      </md-select>
    </div>
    <div layout="row" layout-align="space-between center">
      <span>Choose an Application role</span>
      <md-select
        ng-model="$ctrl.defaultApplicationRole"
        aria-label="Application Role"
        class="md-no-underline"
        ng-disabled="!$ctrl.canChangeDefaultApplicationRole()"
      >
        <md-option ng-repeat="role in $ctrl.applicationRoles" ng-value="role.name" ng-disabled="role.system"> {{role.name}} </md-option>
      </md-select>
    </div>
    <div ng-if="!$ctrl.defaultApiRole && !$ctrl.defaultApplicationRole" style="margin: 0 0 8px 0; text-align: right">
      <em style="color: red">Select at least one role</em>
    </div>
    <form name="formMember" ng-submit="$event.preventDefault()">
      <gv-user-autocomplete users-selected="$ctrl.usersSelected"></gv-user-autocomplete>
    </form>
  </md-dialog-content>

  <md-dialog-actions layout="row">
    <md-button ng-click="$ctrl.hide()"> Cancel </md-button>
    <md-button
      type="submit"
      class="md-raised md-primary"
      ng-click="$ctrl.addMembers()"
      ng-disabled="formMember.$invalid || $ctrl.invalid()"
    >
      Add
    </md-button>
  </md-dialog-actions>
</md-dialog>
